package com.atguigu.lease.common.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author cxt
 * &#064;Description 定义全局异常处理器
 * &#064;create 2025/3/16 下午3:01
 */
@ControllerAdvice
public class GlobalExceptionHandler {
//  @ExceptionHandler 扫描全局异常(参数是要扫描的异常类型)
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(value = leaseException.class)
    @ResponseBody
    public Result leaseError(leaseException e) {
        e.printStackTrace();
        return Result.fail(e.getCode(),e.getMessage());
    }
}
